<?php

use think\migration\Migrator;
use think\migration\db\Column;

class BlackListTable extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    /**
     * Change Method.
     *
     * Create the blacklist table.
     */
    public function change()
    {
        $table = $this->table('think_blacklist', [
            'id' => 'id',
            'signed' => true,
            'auto_increment' => true
        ]);

        $table
            ->addColumn('user_id', 'integer', ['null' => false, 'comment' => '用户ID'])
            ->addColumn('blocked_user_id', 'integer', ['null' => false, 'comment' => '被拉黑用户ID'])
            ->addColumn('reason', 'string', ['limit' => 255, 'null' => true, 'comment' => '拉黑原因'])
            ->addColumn('create_time', 'datetime', ['null' => false, 'comment' => '创建时间'])
            ->addColumn('update_time', 'datetime', ['null' => false, 'comment' => '更新时间'])
            ->addIndex(['user_id', 'blocked_user_id'], ['unique' => true, 'name' => 'idx_user_blocked_user'])
            ->create();
    }
}
